package com.woniuxy.microsysserver.controller;

import com.woniuxy.microsysserver.service.IOutService;
import com.woniuxy.microsysserver.util.IpUtil;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@RequestMapping("/rocket")
@RestController
public class RocketMQController {

    @Resource
    IOutService outServiceImpl;

    /**
     * 向bank02发送转账请求

     * @return
     */
    @PostMapping(value = "/out")
    public String transfer(Integer id,String txNo){
        System.out.println(id);
        //创建一个事务id，作为消息内容发到mq
        if(!StringUtils.hasLength(txNo)){
            txNo = UUID.randomUUID().toString();
        }
        HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String ipAddr = IpUtil.getIpAddr(req);
        outServiceImpl.sendOut(id,txNo,ipAddr);
        return "退出成功";
    }
}
